﻿using System;

namespace awsomeSyntezator.PipeLine.Oscilators
{
	class RedNoise : Oscilator
	{
		public int density;
		public double previous;
        public double goal;
        public double step;
		private Random redNoiseRandomizer;

		public RedNoise(int _density) : base(0, _density, 1)
		{
			type = 0;
			density = _density;
			redNoiseRandomizer = new Random((int)DateTime.Now.Ticks);
            goal = (redNoiseRandomizer.NextDouble() - 0.5) * 2.0;
		}
		public RedNoise(int _density, int strenght) : base(0, _density, strenght)
		{
			type = 0;
			density = _density;
			redNoiseRandomizer = new Random((int)DateTime.Now.Ticks);
            goal = (redNoiseRandomizer.NextDouble() - 0.5) * 2.0;
		}

		public override double getSample(int n, double sample)
		{
			if (density == 0)
				density = 1;
			if( n%density == 0)
			{
				previous = goal;
			    goal = (redNoiseRandomizer.NextDouble() - 0.5)*2.0;

				step = ((goal - previous) / density);
			}
			previous += step;
			return previous;
		}
	}
}
